package re;

import fa.FARule;
import nfa.NFADesign;
import nfa.NFARulebook;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author haoly
 * @title Literal
 * @date 2025/4/17 08:49
 * @description TODO
 */
public class Literal extends Pattern{
    private final Character character;

    public Literal(Character character) {
        this.character = character;
    }

    @Override
    public int precedence() {
        return 3;
    }

    @Override
    public String toString() {
        return this.character.toString();
    }

    @Override
    public NFADesign toNFADesign(){
        Object startState = new Object();
        Object acceptState = new Object();
        Set acceptStates = new HashSet();
        acceptStates.add(acceptState);
        FARule rule = new FARule(startState, character, acceptState);
        List<FARule> rules = new ArrayList<>();
        rules.add(rule);

        NFARulebook rulebook = new NFARulebook(rules);
        return new NFADesign(startState, acceptStates, rulebook);
    }
}
